home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-05 | 38.2 KB | 1,712 lines |
- Path: uunet!olivea!oliveb!veritas!amdcad!sun!exodus!opal.cs.tu-berlin.de
- From: phade@opal.cs.tu-berlin.de (Frank Gadegast)
- Newsgroups: comp.sources.x
- Subject: v13i077: X Font Browser, Part02/02
- Message-ID: <16340@exodus.Eng.Sun.COM>
- Date: 6 Jul 91 07:12:51 GMT
- References: <csx-13i076-font-browser@uunet.UU.NET>
- Sender: news@exodus.Eng.Sun.COM
- Lines: 1700
- Approved: argv@sun.com
-
- Submitted-by: phade@opal.cs.tu-berlin.de (Frank Gadegast)
- Posting-number: Volume 13, Issue 77
- Archive-name: font-browser/part02
-
-
- Second part of xfbrows.
-
- ------------------------------cut here----------------------------
- #!/bin/sh
- # This is a shell archive (produced by shar 3.49)
- # To extract the files from this archive, save it to a file, remove
- # everything above the "!/bin/sh" line above, and type "sh file_name".
- #
- # made 07/01/1991 09:35 UTC by phade@trick
- # Source directory /tmp_mnt/home/all/phade/SRC/Phade/xfb
- #
- # existing files will NOT be overwritten unless -c is specified
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 2346 -rw-r--r-- butt.c
- # 5203 -rw-r--r-- dialog.c
- # 4803 -rw-r--r-- dir.c
- # 2987 -rw-r--r-- list.c
- # 3221 -rw-r--r-- misc.c
- # 6971 -rw-r--r-- scrl.c
- # 8155 -rw-r--r-- xfbrows.c
- #
- # ============= butt.c ==============
- if test -f 'butt.c' -a X"$1" != X"-c"; then
- echo 'x - skipping butt.c (File already exists)'
- else
- echo 'x - extracting butt.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'butt.c' &&
- X
- #include "xfbrows.h"
- #include "bitmaps.h"
- X
- void BTCreate (bp, win, x, y, w, h, str, fg, bg)
- BUTT *bp;
- Window win;
- int x, y, w, h;
- char *str;
- unsigned long fg, bg;
- {
- X bp->win = win;
- X bp->x = x;
- X bp->y = y;
- X bp->w = w;
- X bp->h = h;
- X bp->str = str;
- X bp->fg = fg;
- X bp->bg = bg;
- X bp->lit = 0;
- X bp->active = 1;
- X bp->toggle = 0;
- }
- X
- void BTSetActive (bp, act)
- BUTT *bp;
- int act;
- {
- X if (bp->active != act)
- X {
- X bp->active = act;
- X BTRedraw (bp);
- X }
- }
- X
- void BTRedraw (bp)
- BUTT *bp;
- {
- X int x, y, w, h, r;
- X XPoint poly [9];
- X
- X x = bp->x;
- X y=bp->y;
- X w=bp->w;
- X h=bp->h;
- X r=3;
- X
- X poly [0].x = x;
- X poly [0].y = y+r;
- X poly [1].x = x;
- X poly [1].y = y+h-r;
- X poly [2].x = x+r;
- X poly [2].y = y+h;
- X poly [3].x = x+w-r;
- X poly [3].y = y+h;
- X poly [4].x = x+w;
- X poly [4].y = y+h-r;
- X poly [5].x = x+w;
- X poly [5].y = y+r;
- X poly [6].x = x+w-r;
- X poly [6].y = y;
- X poly [7].x = x+r;
- X poly [7].y = y;
- X poly [8].x = x;
- X poly [8].y = y+r;
- X
- X if (!bp->active) bp->lit = 0;
- X
- X if (bp->lit) XSetForeground (theDisp, theGC, bp->fg);
- X else XSetForeground (theDisp, theGC, bp->bg);
- X XFillPolygon (theDisp, bp->win, theGC, poly, 9, Convex, CoordModeOrigin);
- X
- X XSetForeground (theDisp, theGC, bp->fg);
- X XDrawLines (theDisp, bp->win, theGC, poly, 9, CoordModeOrigin);
- X
- X if (!bp->active)
- X {
- X XSetFillStyle (theDisp, theGC, FillStippled);
- X XSetStipple (theDisp, theGC, grayStip);
- X }
- X
- X if (bp->lit) XSetForeground (theDisp, theGC, bp->bg);
- X else XSetForeground (theDisp, theGC, bp->fg);
- X XDrawString (theDisp, bp->win, theGC, CENTERX (cfinfo, x+w/2, bp->str),
- X CENTERY (cfinfo, y+h/2), bp->str, strlen (bp->str));
- X
- X if (!bp->active) XSetFillStyle (theDisp, theGC, FillSolid);
- }
- X
- int BTTrack (bp)
- BUTT *bp;
- {
- X Window rW, cW;
- X int x, y, rx, ry, rval, inval;
- X unsigned int mask;
- X
- X if (!bp->active) return 0;
- X
- X bp->lit = !bp->lit;
- X inval = bp->lit;
- X
- X BTRedraw (bp);
- X XFlush (theDisp);
- X Timer (75);
- X
- X while (XQueryPointer (theDisp, bp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
- X {
- X if (! (mask & Button1Mask)) break;
- X if (bp->lit!=inval && PTINRECT (x, y, bp->x, bp->y, bp->w, bp->h))
- X bp->lit = inval;BTRedraw (bp);XFlush (theDisp);
- X if (bp->lit==inval && !PTINRECT (x, y, bp->x, bp->y, bp->w, bp->h))
- X bp->lit = !inval;BTRedraw (bp);XFlush (theDisp);
- X }
- X
- X rval = (bp->lit == inval);
- X if (bp->lit && !bp->toggle)
- X {
- X bp->lit = 0;
- X BTRedraw (bp);
- X XFlush (theDisp);
- X }
- X return (rval);
- }
- X
- SHAR_EOF
- chmod 0644 butt.c ||
- echo 'restore of butt.c failed'
- Wc_c="`wc -c < 'butt.c'`"
- test 2346 -eq "$Wc_c" ||
- echo 'butt.c: original size 2346, current size' "$Wc_c"
- fi
- # ============= dialog.c ==============
- if test -f 'dialog.c' -a X"$1" != X"-c"; then
- echo 'x - skipping dialog.c (File already exists)'
- else
- echo 'x - extracting dialog.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'dialog.c' &&
- X
- #include "xfbrows.h"
- X
- int disWIDE, disHIGH;
- #define diaWIDE 470
- #define diaHIGH 105
- X
- #define drawstr1 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- #define drawstr2 "abcdefghijklmnopqrstuvwxyz"
- #define drawstr3 "1234567890[]\\;',./{}|:\"<>?"
- X
- static char title [40];
- static char *diacom, *dianame;
- static char diainfo[50];
- X
- int SimpleEventLoop ();
- X
- char *ShortCutName (name, width)
- char *name;
- int width;
- {
- X char buf [MAXPATHLEN];
- X char nam [MAXPATHLEN];
- X
- X if (StringWidth (name) > width)
- X {
- X strcpy (buf, name);
- X while (StringWidth (buf) > width) buf [strlen(buf)-3]= '\0';
- X strcpy (nam, buf);
- X strcat (nam, "...");
- X }
- X else strcpy (nam, name);
- X return (nam);
- }
- X
- char *maketitle (t)
- char *t;
- {
- X strcpy (title, PROGNAME);
- X strcat (title, " ");
- X strcat (title, t);
- X title [0]= toupper (title [0]);
- }
- X
- void CreateDisW ()
- {
- X int i, l;
- X
- X maketitle ("Font");
- X XSetForeground (theDisp, theGC, infofg);
- X XSetBackground (theDisp, theGC, infobg);
- X SetFonts ();
- X sprintf (diainfo, "Ascent: %d Decent: %d",
- X ASCENT, DESCENT);
- X disWIDE = StringWidth (drawstr1)+30;
- X if ((i = StringWidth (drawstr2)+30) > disWIDE) disWIDE = i;
- X if ((i = StringWidth (drawstr3)+30) > disWIDE) disWIDE = i;
- X SetNormal ();
- X l = StringWidth (diainfo) + 110;
- X if (l > disWIDE) disWIDE = l;
- X if (disWIDE > 570) disWIDE = 570;
- X if (disWIDE < 200) disWIDE = 200;
- X disHIGH = 80+3*LINEHIGH;
- X if (disHIGH > 270) disHIGH = 270;
- X disW = XCreateSimpleWindow (theDisp, dirW, (DIRWIDE-disWIDE)/2,
- X (DIRHIGH-disHIGH)/2, disWIDE-4, disHIGH-4,
- X bwidth, infofg, infobg);
- X if (!disW) FatalError ("can't create dispaly window");
- X XSelectInput (theDisp, disW, ExposureMask | ButtonPressMask);
- X BTCreate (&sbut [S_SOK], disW, disWIDE-80, disHIGH-34, BUTTW, BUTTH,
- X "Ok", infofg, infobg);
- X XMapRaised (theDisp, disW);
- }
- X
- void RedrawDisW ()
- {
- X char str1[50];
- X char str2[50];
- X char str3[50];
- X
- X XSetForeground (theDisp, theGC, infofg);
- X XSetBackground (theDisp, theGC, infobg);
- X SetBold ();
- X XDrawString (theDisp, disW, theGC, (disWIDE-StringWidth (title))/2,
- X 15, title, strlen (title));
- X SetNormal ();
- X XDrawLine (theDisp, disW, theGC, 0, 20, disWIDE, 20);
- X SetBold ();
- X BTRedraw (&sbut [S_SOK]);
- X SetNormal ();
- X SetFonts ();
- X strcpy (str1, drawstr1);
- X strcpy (str2, drawstr2);
- X strcpy (str3, drawstr3);
- X if (dispWIDE = 570)
- X {
- X strcpy (str1, ShortCutName (drawstr1, 520));
- X strcpy (str2, ShortCutName (drawstr2, 520));
- X strcpy (str3, ShortCutName (drawstr3, 520));
- X }
- X XDrawString (theDisp, disW, theGC, 10, 30+LINEHIGH,
- X str1, strlen (str1));
- X if (disHIGH-70-LINEHIGH>LINEHIGH)
- X XDrawString (theDisp, disW, theGC, 10, 30+2*LINEHIGH,
- X str2, strlen (str2));
- X if (disHIGH-70-2*LINEHIGH>LINEHIGH)
- X XDrawString (theDisp, disW, theGC, 10, 30+3*LINEHIGH,
- X str3, strlen (str3));
- X SetNormal ();
- X XDrawString (theDisp, disW, theGC, 10, disHIGH-20,
- X diainfo, strlen (diainfo));
- X XFlush (theDisp);
- }
- X
- int DisplayEventLoop ()
- {
- X return (SimpleEventLoop (disW));
- }
- X
- void CreateDiaW (comment, name)
- char *comment, *name;
- {
- X diacom = comment;
- X dianame = ShortCutName (name, diaWIDE-30);
- X
- X XSetForeground (theDisp, theGC, infofg);
- X XSetBackground (theDisp, theGC, infobg);
- X diaW = XCreateSimpleWindow (theDisp, dirW, (DIRWIDE-diaWIDE)/2,
- X (DIRHIGH-diaHIGH)/2, diaWIDE-8, diaHIGH-8,
- X bwidth + 2, infofg, infobg);
- X if (!diaW) FatalError ("can't create dialog window");
- X XSelectInput (theDisp, diaW, ExposureMask | ButtonPressMask);
- X BTCreate (&sbut [S_SOK], diaW, diaWIDE-80, diaHIGH-35, BUTTW, BUTTH,
- X "Ok", infofg, infobg);
- X XMapRaised (theDisp, diaW);
- }
- X
- void RedrawDiaW ()
- {
- X XSetForeground (theDisp, theGC, infofg);
- X XSetBackground (theDisp, theGC, infobg);
- X SetBold ();
- X XDrawString (theDisp, diaW, theGC, (diaWIDE-StringWidth (title))/2,
- X 15, title, strlen (title));
- X SetNormal ();
- X XDrawLine (theDisp, diaW, theGC, 0, 20, diaWIDE, 20);
- X XDrawString (theDisp, diaW, theGC, 10, 40, diacom, strlen (diacom));
- X XDrawString (theDisp, diaW, theGC, 10, 60, dianame, strlen (dianame));
- X SetBold ();
- X BTRedraw (&sbut [S_SOK]);
- X SetNormal ();
- }
- X
- void CreateErrW (comment, name)
- char *comment, *name;
- {
- X maketitle ("Error");
- X CreateDiaW (comment, name);
- }
- X
- void RedrawErrW ()
- {
- X RedrawDiaW ();
- X XBell (theDisp, 0);
- }
- X
- int ErrorEventLoop ()
- {
- X return (SimpleEventLoop (diaW));
- }
- X
- int SimpleEventLoop (win)
- Window win;
- {
- X XEvent event;
- X BUTT *bp;
- X int end = 1;
- X int ret = 0;
- X
- X XSetForeground (theDisp, theGC, infofg);
- X XSetBackground (theDisp, theGC, infobg);
- X bp = &sbut [S_SOK];
- X
- X XDefineCursor (theDisp, dirW, hand);
- X XDefineCursor (theDisp, win, hand);
- X while (end)
- X {
- X XNextEvent (theDisp, &event);
- X switch (event.type)
- X {
- X case Expose:
- X {
- X XExposeEvent *exp_event = (XExposeEvent *) &event;
- X
- X ExposureWin (exp_event);
- X if (exp_event->window == disW) RedrawDisW ();
- X else if (exp_event->window == diaW) RedrawDiaW ();
- X }
- X break;
- X case ButtonPress:
- X {
- X XButtonEvent *b = (XButtonEvent *) &event;
- X switch (b->button)
- X {
- X case Button1:
- X if (PTINRECT (b->x, b->y, bp->x, bp->y, bp->w, bp->h))
- X if (BTTrack (bp)) end = 0;
- X break;
- X default:
- X break;
- X }
- X }
- X break;
- X default :
- X break;
- X }
- X }
- X XDefineCursor (theDisp, dirW, arrow);
- X XDestroyWindow (theDisp, win);
- X return (ret);
- }
- X
- SHAR_EOF
- chmod 0644 dialog.c ||
- echo 'restore of dialog.c failed'
- Wc_c="`wc -c < 'dialog.c'`"
- test 5203 -eq "$Wc_c" ||
- echo 'dialog.c: original size 5203, current size' "$Wc_c"
- fi
- # ============= dir.c ==============
- if test -f 'dir.c' -a X"$1" != X"-c"; then
- echo 'x - skipping dir.c (File already exists)'
- else
- echo 'x - extracting dir.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'dir.c' &&
- X
- #include "xfbrows.h"
- #include "bitmaps.h"
- X
- #define MAXNAMES 10000
- X
- #define LISTW 565
- #define DDWIDE LISTW-80+15
- #define MAXDEEP 30
- #define MAXFNLEN 40
- #define DEFFILENAME ""
- X
- static int listh;
- static int numdirnames = 0;
- static int toomuchfonts = 0;
- static char filename [MAXPATHLEN];
- static char typename [MAXPATHLEN];
- X
- static void RedrawDList ();
- static int dnamcmp ();
- X
- void CreateDirW (geom)
- char *geom;
- {
- X char message[50];
- X
- X listh = LINEHIGH * NLINES;
- X
- X dirW = CreateWindow (PROGNAME, geom, DIRWIDE, DIRHIGH, infofg, infobg);
- X if (!dirW) FatalError ("couldn't create window!");
- X
- X dnamW = XCreateSimpleWindow (theDisp, dirW, 10, listh+46-ASCENT,
- X 510, LINEHIGH+4, 1, infofg, infobg);
- X if (!dnamW) FatalError ("can't create window");
- X XSelectInput (theDisp, dnamW, ExposureMask);
- X
- X grayStip = XCreatePixmapFromBitmapData (theDisp, dirW, gray50_bits,
- X gray50_width, gray50_height, 1, 0, 1);
- X
- X LSCreate (&dList, dirW, 10, LINEHIGH-5, LISTW, listh, NLINES,
- X dirnames, numdirnames,
- X infofg, infobg, RedrawDList, 1, 0);
- X
- X BTCreate (&dbut [S_BQUIT], dirW, 530, listh+47-ASCENT, BUTTW, BUTTH,
- X "Quit", infofg, infobg);
- X
- X SetTypeName (DEFFILENAME);
- X LoadCurrentDirectory ();
- X XMapSubwindows (theDisp, dirW);
- X XSelectInput (theDisp, dirW, ExposureMask | ButtonPressMask | KeyPressMask);
- X XMapRaised (theDisp, dirW);
- X XDefineCursor (theDisp, dirW, arrow);
- X if (toomuchfonts)
- X {
- X sprintf (message, "There are more than %d fonts !!!", MAXNAMES);
- X CreateErrW (message, "Reconfigure and recompile !!!");
- X RedrawErrW ();
- X ErrorEventLoop ();
- X }
- }
- X
- void RedrawDirW (x, y, w, h)
- int x, y, w, h;
- {
- X int ypos;
- X char foo [30];
- X XRectangle xr;
- X
- X xr.x = x;
- X xr.y = y;
- X xr.width = w;
- X xr.height = h;
- X XSetClipRectangles (theDisp, theGC, 0, 0, &xr, 1, Unsorted);
- X
- X ypos = 4 + ASCENT;
- X XSetForeground (theDisp, theGC, infobg);
- X XFillRectangle (theDisp, dirW, theGC, 10, ypos-ASCENT, DIRWIDE, CHIGH);
- X XSetForeground (theDisp, theGC, infofg);
- X
- X if (dList.nstr==1) strcpy (foo, "1 font");
- X else sprintf (foo, "%d fonts", dList.nstr);
- X
- X ypos = dList.y + dList.h + 5 + ASCENT;
- X XSetForeground (theDisp, theGC, infobg);
- X XFillRectangle (theDisp, dirW, theGC, 10, ypos-ASCENT, DIRWIDE, CHIGH);
- X XSetForeground (theDisp, theGC, infofg);
- X SetBold ();
- X XDrawString (theDisp, dirW, theGC, 10, ypos, foo, strlen (foo));
- X SetNormal ();
- X
- X SetBold ();
- X BTRedraw (&dbut [S_BQUIT]);
- X SetNormal ();
- X
- X XSetClipMask (theDisp, theGC, None);
- }
- X
- int ClickDirW (x, y)
- int x, y;
- {
- X BUTT *bp;
- X int bnum;
- X
- X for (bnum=0;bnum<S_NBUTTS;bnum++)
- X {
- X bp = &dbut [bnum];
- X if (PTINRECT (x, y, bp->x, bp->y, bp->w, bp->h)) break;
- X }
- X if (bnum<S_NBUTTS) if (BTTrack (bp)) return (bnum);
- X return -1;
- }
- X
- void SelectDir (n)
- int n;
- {
- X SetDirFName (dList.str [n]);
- X if ((disfinfo = XLoadQueryFont (theDisp, filename)) == NULL)
- X {
- X CreateErrW ("Unable to load font:", filename);
- X RedrawErrW ();
- X ErrorEventLoop ();
- X return;
- X }
- X CreateDisW ();
- X RedrawDisW ();
- X DisplayEventLoop ();
- }
- X
- static void RedrawDList ()
- {
- X LSRedraw (&dList);
- }
- X
- void SetFonts ()
- {
- X disfont = disfinfo->fid;
- X XSetForeground (theDisp, theGC, infofg);
- X XSetBackground (theDisp, theGC, infobg);
- X XSetFont (theDisp, theGC, disfont);
- X cfinfo = disfinfo;
- }
- X
- void LoadCurrentDirectory ()
- {
- X int i;
- X
- X dirnames = XListFonts (theDisp, "*", MAXNAMES, &numdirnames);
- X if (numdirnames == MAXNAMES) toomuchfonts = 1;
- X qsort ((char *) dirnames, numdirnames, sizeof (char *), dnamcmp);
- X LSNewData (&dList, dirnames, numdirnames);
- X RedrawDirW (0, 0, DIRWIDE, DIRHIGH);
- X SetDirFName (DEFFILENAME);
- }
- X
- static int dnamcmp (s1, s2)
- char **s1, **s2;
- {
- X return (strcmp ((*s1), (*s2)));
- }
- X
- int DirKey (c)
- int c;
- {
- X int len;
- X
- X len = strlen (typename);
- X
- X if (c>' ' && c<'\177')
- X {
- X if (c=='/') return (-1);
- X if (len >= MAXFNLEN-1) return (-1);
- X typename [len]=c;
- X typename [len+1]='\0';
- X }
- X else if (c=='\010' || c=='\177')
- X {
- X if (len==0) return (-1);
- X typename [len-1]='\0';
- X }
- X else if (c=='\025') strcpy (typename, "");
- X else if (c==13)
- X {
- X if (strlen (typename) == 0) return (-1);
- X strcpy (filename, typename);
- X if ((disfinfo = XLoadQueryFont (theDisp, filename)) == NULL)
- X {
- X CreateErrW ("Unable to load font:", filename);
- X RedrawErrW ();
- X ErrorEventLoop ();
- X return (0);
- X }
- X CreateDisW ();
- X RedrawDisW ();
- X DisplayEventLoop ();
- X strcpy (typename, "");
- X }
- X else return (-1);
- X
- X SetTypeName (typename);
- X return (0);
- }
- X
- void RedrawDNamW ()
- {
- X int width, len;
- X
- X len = strlen (typename);
- X XSetForeground (theDisp, theGC, infofg);
- X XDrawString (theDisp, dnamW, theGC, 3, ASCENT+3, typename, len);
- X width = StringWidth (typename);
- X XDrawLine (theDisp, dnamW, theGC, 3+width+1, 3, 3+width+1, 3+CHIGH);
- }
- X
- void SetDirFName (st)
- char *st;
- {
- X strcpy (filename, st);
- }
- X
- void SetTypeName (st)
- char *st;
- {
- X strcpy (typename, st);
- X XClearWindow (theDisp, dnamW);
- X RedrawDNamW ();
- }
- X
- SHAR_EOF
- chmod 0644 dir.c ||
- echo 'restore of dir.c failed'
- Wc_c="`wc -c < 'dir.c'`"
- test 4803 -eq "$Wc_c" ||
- echo 'dir.c: original size 4803, current size' "$Wc_c"
- fi
- # ============= list.c ==============
- if test -f 'list.c' -a X"$1" != X"-c"; then
- echo 'x - skipping list.c (File already exists)'
- else
- echo 'x - extracting list.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'list.c' &&
- X
- #include "xfbrows.h"
- #include "bitmaps.h"
- X
- #define DBLCLKTIME 500
- #define LISTW 330
- #define pixlineheight 13
- X
- #define INACTIVE(lptr, item) ((lptr)->filetypes && (lptr)->dirsonly && \
- X (item) >= 0 && (item) < (lptr)->nstr && \
- X (lptr)->str[(item)][0] != C_DIR && \
- X (lptr)->str[(item)][0] != C_LNK)
- X
- static void drawSel ();
- X
- void LSCreate (lp, win, x, y, w, h, nlines, strlist, nstr, fg, bg, fptr,
- X typ, donly)
- LIST *lp;
- Window win;
- int x, y, w, h, nlines, nstr, typ, donly;
- unsigned long fg, bg;
- char **strlist;
- void (*fptr) ();
- {
- X lp->win = XCreateSimpleWindow (theDisp, win, x, y, w, h, 1, infofg, infobg);
- X if (!lp->win) FatalError ("can't create list window!");
- X
- X lp->x = x;
- X lp->y = y;
- X lp->w = w;
- X lp->h = h;
- X lp->fg = fg;
- X lp->bg = bg;
- X lp->str = strlist;
- X lp->nstr = nstr;
- X lp->selected = 0;
- X lp->nlines = nlines;
- X lp->filetypes= typ;
- X lp->dirsonly = donly;
- X
- X XSelectInput (theDisp, lp->win, ExposureMask | ButtonPressMask
- X | ButtonReleaseMask | Button1MotionMask | EnterWindowMask
- X | LeaveWindowMask);
- X
- X SCCreate (&lp->scrl, win, x+w, y, 1, h, 0, nstr-nlines, curname, nlines-1,
- X fg, bg, fptr);
- }
- X
- void LSNewData (lp, strlist, nstr)
- LIST *lp;
- char **strlist;
- int nstr;
- {
- X lp->str = strlist;
- X lp->nstr = nstr;
- X lp->selected = 0;
- X SCSetRange (&lp->scrl, 0, nstr - lp->nlines, 0, lp->nlines-1);
- }
- X
- static void drawSel (lp, j)
- LIST *lp;
- int j;
- {
- X int i, inactive;
- X unsigned long fg, bg;
- X
- X inactive = INACTIVE (lp, j);
- X
- X i = j - lp->scrl.val;
- X if (i<0 || i>=lp->nlines) return;
- X
- X if (j == lp->selected && !inactive && j<lp->nstr)
- X {
- X fg = lp->bg;
- X bg = lp->fg;
- X }
- X else
- X {
- X fg = lp->fg;
- X bg = lp->bg;
- X }
- X
- X XSetForeground (theDisp, theGC, bg);
- X XFillRectangle (theDisp, lp->win, theGC, 0, i*LINEHIGH, lp->w, LINEHIGH);
- X
- X if (j>=0 && j<lp->nstr)
- X {
- X XSetForeground (theDisp, theGC, fg);
- X XSetBackground (theDisp, theGC, bg);
- X
- X if (!lp->filetypes)
- X XDrawString (theDisp, lp->win, theGC, 3, i*LINEHIGH + ASCENT + 1,
- X lp->str [j], strlen (lp->str [j]));
- X else
- X {
- X XDrawString (theDisp, lp->win, theGC, 6,
- X i*LINEHIGH + ASCENT + 1,
- X lp->str [j], strlen (lp->str [j]));
- X }
- X }
- }
- X
- void LSRedraw (lp)
- LIST *lp;
- {
- X int i;
- X
- X for (i = lp->scrl.val;i < lp->scrl.val + lp->nlines;i++) drawSel (lp, i);
- }
- X
- int LSClick (lp, ev)
- LIST *lp;
- XXButtonEvent *ev;
- {
- X Window rW, cW;
- X int rx, ry, x, y, sel, oldsel;
- X unsigned int mask;
- X static Time lasttime=0;
- X static int lastsel = -1;
- X
- X x = ev->x;
- X y = ev->y;
- X sel = lp->scrl.val + y/LINEHIGH;
- X if (sel >= lp->nstr) sel = lp->selected;
- X
- X if (ev->time - lasttime < DBLCLKTIME && sel==lastsel
- X && (lp->scrl.val + y/LINEHIGH) < lp->nstr
- X && !INACTIVE (lp, sel)) return (sel);
- X
- X lasttime = ev->time;lastsel = sel;
- X
- X if (sel != lp->selected)
- X {
- X oldsel = lp->selected;
- X lp->selected = sel;
- X drawSel (lp, sel);
- X drawSel (lp, oldsel);
- X XFlush (theDisp);
- X }
- X
- X while (XQueryPointer (theDisp, lp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
- X {
- X if (! (mask & Button1Mask)) break;
- X }
- X
- X return (sel);
- }
- X
- SHAR_EOF
- chmod 0644 list.c ||
- echo 'restore of list.c failed'
- Wc_c="`wc -c < 'list.c'`"
- test 2987 -eq "$Wc_c" ||
- echo 'list.c: original size 2987, current size' "$Wc_c"
- fi
- # ============= misc.c ==============
- if test -f 'misc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping misc.c (File already exists)'
- else
- echo 'x - extracting misc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'misc.c' &&
- X
- #define NEEDSTIME
- #include "xfbrows.h"
- X
- static int timerdone;
- X
- Window CreateWindow (name, geom, w, h, fg, bg)
- char *name, *geom;
- unsigned int w, h;
- unsigned long fg, bg;
- {
- X Window win;
- X XSetWindowAttributes xswa;
- X unsigned int xswamask;
- X XWMHints xwmh;
- X XSizeHints hints;
- X int i, x, y;
- X int a, b;
- X
- X x = y = 1;
- X i = XParseGeometry (geom, &x, &y, &a, &b);
- X if (i&XValue || i&YValue) hints.flags = USPosition;
- X else hints.flags = PPosition;
- X
- X hints.flags |= USSize;
- X
- X if (i&XValue && i&XNegative) x = dispWIDE - w - abs (x);
- X if (i&YValue && i&YNegative) y = dispHIGH - h - abs (y);
- X
- X hints.x = x;
- X hints.y = y;
- X hints.width = w;
- X hints.height = h;
- X hints.min_width = w;
- X hints.min_height = h;
- X hints.max_width = w;
- X hints.max_height = h;
- X hints.flags |= PMaxSize | PMinSize;
- X
- X xswa.background_pixel = bg;
- X xswa.border_pixel = fg;
- X xswamask = CWBackPixel | CWBorderPixel;
- X
- X win = XCreateWindow (theDisp, rootW, x, y, w, h,
- X bwidth, CopyFromParent, CopyFromParent,
- X CopyFromParent, xswamask, &xswa);
- X if (!win) return (win);
- X
- X XSetStandardProperties (theDisp, win, name, name, None, NULL, 0, &hints);
- X
- X xwmh.input = True;
- X xwmh.flags = InputHint;
- X if (icongeom)
- X {
- X i = XParseGeometry (icongeom, &x, &y, &a, &b);
- X if ((i&XValue && i&XNegative) ||
- X (i&YValue && i&YNegative))
- X FatalError ("can't parse negativ icon position");
- X if (i&XValue) xwmh.icon_x = x;
- X if (i&YValue) xwmh.icon_y = y;
- X xwmh.flags |= IconPositionHint;
- X }
- X if (iconic)
- X {
- X xwmh.flags |= StateHint;
- X xwmh.initial_state = IconicState;
- X }
- X
- X XSetWMHints (theDisp, win, &xwmh);
- X
- X return (win);
- }
- X
- void SetBold ()
- {
- X XSetFont (theDisp, theGC, bfont);
- X cfinfo = bfinfo;
- }
- X
- void SetNormal ()
- {
- X XSetFont (theDisp, theGC, mfont);
- X cfinfo = mfinfo;
- }
- X
- int StringWidth (str)
- char *str;
- {
- X return (XTextWidth (cfinfo, str, strlen (str)));
- }
- X
- void ExposureWin (exp_event)
- XXExposeEvent *exp_event;
- {
- X if (exp_event->count>0 && exp_event->window != dirW) return;
- X else if (exp_event->window == dirW)
- X RedrawDirW (exp_event->x, exp_event->y,
- X exp_event->width, exp_event->height);
- X else if (exp_event->window == dList.win) LSRedraw (&dList);
- X else if (exp_event->window == dList.scrl.win) SCRedraw (&dList.scrl);
- X else if (exp_event->window == dnamW) RedrawDNamW ();
- }
- X
- void FatalError (identifier)
- char *identifier;
- {
- X fprintf (stderr, "%s: %s\n", cmd, identifier);
- X Quit (-1);
- }
- X
- static void FreeMostResources ()
- {
- X if (!theDisp) return;
- X if (dirW) XDestroyWindow (theDisp, dirW);
- X XFreeFontNames (dirnames);
- X XFlush (theDisp);
- }
- X
- void Quit (i)
- int i;
- {
- X FreeMostResources ();
- X exit (i);
- }
- X
- static void onalarm ()
- {
- X timerdone=1;
- }
- X
- void Timer (n)
- int n;
- {
- X long usec;
- X struct itimerval it;
- X
- X if (!n) return;
- X
- #ifdef SCO
- X if (!n) return;
- X nap (n);
- X return;
- #else
- X
- #ifdef USLEEP
- X usleep (n);
- X return;
- #else
- X
- #ifdef NOTIMER
- X return;
- #else
- X
- X usec = (long) n * 1000;
- X
- X memset (&it, 0, sizeof (it));
- X if (usec>=1000000L)
- X {
- X it.it_value.tv_sec = usec / 1000000L;
- X usec %= 1000000L;
- X }
- X
- X it.it_value.tv_usec = usec;
- X timerdone=0;
- X signal (SIGALRM, onalarm);
- X setitimer (ITIMER_REAL, &it, (struct itimerval *)0);
- X while (1)
- X {
- X HOLD_SIG;
- X if (timerdone) break;
- X else PAUSE_SIG;
- X }
- X RELEASE_SIG;
- X signal (SIGALRM, SIG_DFL);
- #endif
- #endif
- #endif
- }
- X
- SHAR_EOF
- chmod 0644 misc.c ||
- echo 'restore of misc.c failed'
- Wc_c="`wc -c < 'misc.c'`"
- test 3221 -eq "$Wc_c" ||
- echo 'misc.c: original size 3221, current size' "$Wc_c"
- fi
- # ============= scrl.c ==============
- if test -f 'scrl.c' -a X"$1" != X"-c"; then
- echo 'x - skipping scrl.c (File already exists)'
- else
- echo 'x - extracting scrl.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'scrl.c' &&
- X
- #include "xfbrows.h"
- #include "bitmaps.h"
- X
- #define UPLINE 0
- #define UPPAGE 1
- #define DNLINE 2
- #define DNPAGE 3
- #define THUMB 4
- #define SCRLWAIT 150
- X
- static Pixmap upPix, downPix;
- static Pixmap up1Pix, down1Pix;
- static Pixmap sgray;
- static int pixmaps_built=0;
- X
- static int whereInScrl ();
- static void drawArrow ();
- X
- void SCCreate (sp, parent, x, y, vert, len, minv, maxv, curv, page,
- X fg, bg, func)
- SCRL *sp;
- Window parent;
- int x, y, vert, len, minv, maxv, curv, page;
- unsigned long fg, bg;
- void (*func) ();
- {
- X if (!pixmaps_built)
- X {
- X upPix = XCreatePixmapFromBitmapData (theDisp, parent,
- X up_bits, up_width, up_height, fg, bg, dispDEEP);
- X downPix = XCreatePixmapFromBitmapData (theDisp, parent,
- X down_bits, down_width, down_height, fg, bg, dispDEEP);
- X up1Pix = XCreatePixmapFromBitmapData (theDisp, parent,
- X up1_bits, up1_width, up1_height, fg, bg, dispDEEP);
- X down1Pix = XCreatePixmapFromBitmapData (theDisp, parent,
- X down1_bits, down1_width, down1_height, fg, bg, dispDEEP);
- X sgray = XCreatePixmapFromBitmapData (theDisp, parent,
- X scrlgray_bits, scrlgray_width, scrlgray_height, fg, bg, dispDEEP);
- X }
- X
- X sp->vert = vert;
- X sp->len = len;
- X sp->fg = fg;
- X sp->bg = bg;
- X sp->uplit = sp->dnlit = 0;
- X
- X if (vert)
- X sp->win = XCreateSimpleWindow (theDisp, parent, x, y, up_width-2,
- X len, 1, fg, bg);
- X else FatalError ("don't know HOW to make horizontal scrollbar");
- X
- X if (!sp->win) FatalError ("can't create scrollbar window");
- X
- X sp->tsize = up_width-2;
- X sp->tmin = up_height-1;
- X sp->tmax = len - (up_height-1) - sp->tsize;
- X sp->drawobj = func;
- X
- X SCSetRange (sp, minv, maxv, curv, page);
- X XSelectInput (theDisp, sp->win, ExposureMask | ButtonPressMask);
- }
- X
- void SCSetRange (sp, minv, maxv, curv, page)
- SCRL *sp;
- int minv, maxv, curv, page;
- {
- X if (maxv<minv) maxv=minv;
- X sp->min = minv;
- X sp->max = maxv;
- X sp->page = page;
- X sp->active = (minv < maxv);
- X
- X if (sp->active) XSetWindowBackgroundPixmap (theDisp, sp->win, sgray);
- X else XSetWindowBackground (theDisp, sp->win, sp->bg);
- X
- X SCSetVal (sp, curv);
- }
- X
- void SCSetVal (sp, curv)
- SCRL *sp;
- int curv;
- {
- X RANGE (curv, sp->min, sp->max);
- X sp->val = curv;
- X
- X if (sp->active)
- X sp->tpos = sp->tmin + ((sp->tmax - sp->tmin)* (curv - sp->min))
- X / (sp->max - sp->min);
- X SCRedraw (sp);
- X (sp->drawobj) ();
- X XFlush (theDisp);
- }
- X
- void SCRedraw (sp)
- SCRL *sp;
- {
- X XSetForeground (theDisp, theGC, sp->fg);
- X XSetBackground (theDisp, theGC, sp->bg);
- X
- X XClearWindow (theDisp, sp->win);
- X
- X if (sp->vert)
- X {
- X drawArrow (sp, UPLINE);
- X drawArrow (sp, DNLINE);
- X
- X if (sp->active)
- X {
- X XSetForeground (theDisp, theGC, sp->bg);
- X XFillRectangle (theDisp, sp->win, theGC,
- X 1, sp->tpos+1, sp->tsize-2, sp->tsize-2);
- X XSetForeground (theDisp, theGC, sp->fg);
- X XDrawRectangle (theDisp, sp->win, theGC,
- X 0, sp->tpos, sp->tsize-1, sp->tsize-1);
- X }
- X }
- }
- X
- static int whereInScrl (sp, x, y)
- SCRL *sp;
- int x, y;
- {
- X int v;
- X
- X v=0;
- X if (sp->vert)
- X {
- X if (x<0 || x>up_width-2 || y<0 || y>sp->len) return -1;
- X v = y;
- X }
- X
- X if (v < sp->tmin) return UPLINE;
- X if (sp->active)
- X {
- X if (v < sp->tpos) return UPPAGE;
- X if (v < sp->tpos + sp->tsize) return THUMB;
- X if (v <= sp->tmax + sp->tsize) return DNPAGE;
- X }
- X if (v > sp->tmax+sp->tsize) return DNLINE;
- X
- X return -1;
- }
- X
- static void drawArrow (sp, arr)
- SCRL *sp;
- int arr;
- {
- X if (arr == UPLINE)
- X {
- X if (sp->uplit)
- X XCopyArea (theDisp, up1Pix, sp->win, theGC, 0, 0,
- X up_width, up_height, -1, -1);
- X else XCopyArea (theDisp, upPix, sp->win, theGC, 0, 0,
- X up_width, up_height, -1, -1);
- X }
- X else if (arr == DNLINE)
- X {
- X if (sp->dnlit)
- X XCopyArea (theDisp, down1Pix, sp->win, theGC, 0, 0,
- X up_width, up_height, -1, sp->len- (up_height-1));
- X else XCopyArea (theDisp, downPix, sp->win, theGC, 0, 0,
- X up_width, up_height, -1, sp->len- (up_height-1));
- X }
- X XFlush (theDisp);
- }
- X
- void SCTrack (sp, mx, my)
- SCRL *sp;
- int mx, my;
- {
- X Window rW, cW;
- X int rx, ry, x, y, ipos, pos, lit, ty, tyoff, ty1;
- X unsigned int mask;
- X
- X ty = tyoff = 0;
- X
- X XSetForeground (theDisp, theGC, sp->fg);
- X XSetBackground (theDisp, theGC, sp->bg);
- X
- X ipos = whereInScrl (sp, mx, my);
- X lit = 1;
- X
- X switch (ipos)
- X {
- X case UPLINE:
- X sp->uplit = 1;
- X if (sp->val > sp->min) SCSetVal (sp, sp->val-1);
- X Timer (SCRLWAIT);
- X break;
- X case DNLINE:
- X sp->dnlit = 1;
- X if (sp->val < sp->max) SCSetVal (sp, sp->val+1);
- X Timer (SCRLWAIT);
- X break;
- X case UPPAGE:
- X SCSetVal (sp, sp->val - sp->page);
- X break;
- X case DNPAGE:
- X SCSetVal (sp, sp->val + sp->page);
- X break;
- X case THUMB:
- X tyoff = sp->tpos - my;
- X ty = sp->tpos;
- X if (sp->fg == black)
- X XSetState (theDisp, theGC, sp->bg, sp->fg, GXinvert,
- X sp->fg ^ sp->bg);
- X else
- X XSetState (theDisp, theGC, sp->fg, sp->bg, GXinvert,
- X sp->fg ^ sp->bg);
- X XDrawRectangle (theDisp, sp->win, theGC,
- X 0, sp->tpos, sp->tsize-1, sp->tsize-1);
- X break;
- X }
- X
- X while (XQueryPointer (theDisp, sp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
- X {
- X if (! (mask & Button1Mask)) break;
- X switch (ipos)
- X {
- X case THUMB:
- X if (x<-16 || x>16+sp->tsize)
- X {
- X if (lit)
- X {
- X lit = 0;
- X XDrawRectangle (theDisp, sp->win, theGC, 0, ty,
- X sp->tsize-1, sp->tsize-1);
- X }
- X }
- X else
- X {
- X if (!lit)
- X {
- X lit = 1;
- X ty = y + tyoff;
- X RANGE (ty, sp->tmin, sp->tmax);
- X XDrawRectangle (theDisp, sp->win, theGC, 0, ty,
- X sp->tsize-1, sp->tsize-1);
- X }
- X else
- X {
- X ty1 = y+tyoff;
- X RANGE (ty1, sp->tmin, sp->tmax);
- X if (ty != ty1)
- X {
- X XDrawRectangle (theDisp, sp->win, theGC,
- X 0, ty, sp->tsize-1, sp->tsize-1);
- X ty = ty1;
- X XDrawRectangle (theDisp, sp->win, theGC,
- X 0, ty, sp->tsize-1, sp->tsize-1);
- X }
- X }
- X }
- X break;
- X case UPLINE:
- X case DNLINE:
- X pos = whereInScrl (sp, x, y);
- X if (pos == ipos)
- X {
- X if (!lit)
- X {
- X lit = 1;
- X if (ipos == UPLINE)
- X {
- X sp->uplit = 1;
- X drawArrow (sp, UPLINE);
- X }
- X else
- X {
- X sp->dnlit = 1;
- X drawArrow (sp, DNLINE);
- X }
- X }
- X else
- X {
- X if (sp->val > sp->min && pos==UPLINE)
- X {
- X SCSetVal (sp, sp->val-1);
- X Timer (SCRLWAIT);
- X }
- X else if (sp->val < sp->max && pos==DNLINE)
- X {
- X SCSetVal (sp, sp->val+1);
- X Timer (SCRLWAIT);
- X }
- X }
- X }
- X else
- X {
- X if (lit)
- X {
- X lit = 0;
- X if (ipos == UPLINE)
- X {
- X sp->uplit = 0;
- X drawArrow (sp, UPLINE);
- X }
- X else
- X {
- X sp->dnlit = 0;
- X drawArrow (sp, DNLINE);
- X }
- X }
- X }
- X break;
- X }
- X }
- X
- X if (ipos == THUMB)
- X {
- X if (lit)
- X XDrawRectangle (theDisp, sp->win, theGC, 0, ty,
- X sp->tsize-1, sp->tsize-1);
- X XSetState (theDisp, theGC, sp->fg, sp->bg, GXcopy, AllPlanes);
- X
- X if (lit && ty != sp->tpos)
- X {
- X int dt, dv;
- X dt = sp->tmax - sp->tmin;
- X dv = sp->max - sp->min;
- X SCSetVal (sp, sp->min + (dv* (ty - sp->tmin)+dt/2) / dt);
- X }
- X }
- X
- X if (lit && ipos == UPLINE)
- X {
- X sp->uplit = 0;
- X drawArrow (sp, UPLINE);
- X }
- X if (lit && ipos == DNLINE)
- X {
- X sp->dnlit = 0;
- X drawArrow (sp, DNLINE);
- X }
- }
- X
- SHAR_EOF
- chmod 0644 scrl.c ||
- echo 'restore of scrl.c failed'
- Wc_c="`wc -c < 'scrl.c'`"
- test 6971 -eq "$Wc_c" ||
- echo 'scrl.c: original size 6971, current size' "$Wc_c"
- fi
- # ============= xfbrows.c ==============
- if test -f 'xfbrows.c' -a X"$1" != X"-c"; then
- echo 'x - skipping xfbrows.c (File already exists)'
- else
- echo 'x - extracting xfbrows.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'xfbrows.c' &&
- /* --- C ---
- **********************************************************************
- *
- * Filename : Xfbrows
- * Description : XWindow font browser
- *
- * Last modified : 1 April 1990
- * Version : 2.0
- * Language : C
- * For machine : INTERACTIVE Unix
- * Status : Ready to publish
- * Compile as : Makefile
- *
- * Programed by : Phade
- * Developed by : Phade Software
- * Contact : phade@cs.tu-berlin.de
- *
- * Copyright (c) 1991 by Phade Software
- *
- **********************************************************************
- */
- X
- #define MAIN
- #include "xfbrows.h"
- #include <X11/Xatom.h>
- X
- #define QUIT -1
- #define FONT "-*-helvetica-medium-r-*-*-12-*"
- #define BFONT "-*-helvetica-bold-r-*-*-12-*"
- X
- /* #define FONT "-*-courier-medium-r-*-*-12-*"
- X #define BFONT "-*-courier-bold-r-*-*-12-*" */
- X
- /* #define FONT "8x13"
- X #define BFONT "8x13bold" */
- X
- static unsigned long rootbg, rootfg;
- static char *maingeom = NULL;
- X
- static Atom __SWM_VROOT = None;
- static char str [128];
- static char *def_str;
- static int def_int;
- X
- static void Syntax ();
- static int EventLoop ();
- static int rd_int ();
- static int rd_str ();
- static int rd_flag ();
- X
- int main (argc, argv)
- int argc;
- char *argv [];
- {
- X int i;
- X char *display, *whitestr, *blackstr, *fgstr, *bgstr;
- X char *rootfgstr, *rootbgstr;
- X
- X XColor ecdef;
- X Window rootReturn, parentReturn, *children;
- X unsigned int numChildren;
- X
- X display = whitestr = blackstr = NULL;
- X fgstr = bgstr = rootfgstr = rootbgstr = NULL;
- X cmd = rindex (argv [0], '/');
- X if (!cmd) cmd = argv [0];
- X else cmd++;
- X
- X ncols = -1;
- X mono = 0;
- X bwidth = 2;
- X
- X dirW = disW = NULL;
- X icongeom = NULL;
- X iconic = 0;
- X
- X curname = 0;
- X
- X for (i=1;i<argc-1;i++)
- X {
- X if (!strncmp (argv [i], "-d", 2))
- X {
- X display = argv [++i];
- X break;
- X }
- X }
- X
- X if ((theDisp=XOpenDisplay (display)) == NULL)
- X {
- X fprintf (stderr, "%s: Can't open display\n", argv [0]);
- X Quit (-1);
- X }
- X
- X if (rd_str ("geometry")) maingeom = def_str;
- X if (rd_str ("icongeom")) icongeom = def_str;
- X if (rd_str ("background")) bgstr = def_str;
- X if (rd_str ("foreground")) fgstr = def_str;
- X if (rd_int ("borderWidth")) bwidth = def_int;
- X iconic = rd_flag ("iconic");
- X
- X numnames = 0;
- X for (i=1;i<argc;i++)
- X {
- X if (argv [i][0]!= '-') Syntax ();
- X else if (!strncmp (argv [i], "-bg", 3))
- X { if (++i<argc) bgstr = argv [i]; }
- X else if (!strncmp (argv [i], "-bw", 3))
- X { if (++i<argc) bwidth=atoi (argv [i]); }
- X else if (!strncmp (argv [i], "-d", 2))
- X { if (++i<argc) display = argv [i]; }
- X else if (!strncmp (argv [i], "-fg", 3))
- X { if (++i<argc) fgstr = argv [i]; }
- X else if (!strncmp (argv [i], "-ge", 3))
- X { if (++i<argc) maingeom = argv [i]; }
- X else if (!strncmp (argv [i], "-icong", 6))
- X { if (++i<argc) icongeom = argv [i]; }
- X else if (!strncmp (argv [i], "-iconi", 6)) iconic = 1;
- X else Syntax ();
- X }
- X
- X theScreen = DefaultScreen (theDisp);
- X theCmap = DefaultColormap (theDisp, theScreen);
- X rootW = RootWindow (theDisp, theScreen);
- X theGC = DefaultGC (theDisp, theScreen);
- X theVisual = DefaultVisual (theDisp, theScreen);
- X ncells = DisplayCells (theDisp, theScreen);
- X dispWIDE = DisplayWidth (theDisp, theScreen);
- X dispHIGH = DisplayHeight (theDisp, theScreen);
- X dispDEEP = DisplayPlanes (theDisp, theScreen);
- X
- X __SWM_VROOT = XInternAtom (theDisp, "__SWM_VROOT", False);
- X XQueryTree (theDisp, rootW, &rootReturn, &parentReturn, &children,
- X &numChildren);
- X for (i = 0;i < numChildren;i++)
- X {
- X Atom actual_type;
- X int actual_format;
- X unsigned long nitems, bytesafter;
- X Window *newRoot = NULL;
- X XWindowAttributes xwa;
- X
- X if (XGetWindowProperty (theDisp, children [i], __SWM_VROOT, 0, 1,
- X False, XA_WINDOW, &actual_type, &actual_format, &nitems,
- X &bytesafter, (unsigned char **) &newRoot) == Success && newRoot)
- X {
- X rootW = *newRoot;
- X XGetWindowAttributes (theDisp, rootW, &xwa);
- X dispWIDE = xwa.width;dispHIGH = xwa.height;
- X dispDEEP = xwa.depth;
- X break;
- X }
- X }
- X
- X arrow = XCreateFontCursor (theDisp, XC_top_left_arrow);
- X target = XCreateFontCursor (theDisp, XC_leftbutton);
- X hand = XCreateFontCursor (theDisp, XC_hand1);
- X
- X white = WhitePixel (theDisp, theScreen);
- X black = BlackPixel (theDisp, theScreen);
- X if (whitestr && XParseColor (theDisp, theCmap, whitestr, &ecdef) &&
- X XAllocColor (theDisp, theCmap, &ecdef)) white = ecdef.pixel;
- X if (blackstr && XParseColor (theDisp, theCmap, blackstr, &ecdef) &&
- X XAllocColor (theDisp, theCmap, &ecdef)) black = ecdef.pixel;
- X
- X fg = black;
- X bg = white;
- X if (fgstr && XParseColor (theDisp, theCmap, fgstr, &ecdef) &&
- X XAllocColor (theDisp, theCmap, &ecdef)) fg = ecdef.pixel;
- X if (bgstr && XParseColor (theDisp, theCmap, bgstr, &ecdef) &&
- X XAllocColor (theDisp, theCmap, &ecdef)) bg = ecdef.pixel;
- X
- X rootfg = white;
- X rootbg = black;
- X if (rootfgstr && XParseColor (theDisp, theCmap, rootfgstr, &ecdef) &&
- X XAllocColor (theDisp, theCmap, &ecdef)) rootfg = ecdef.pixel;
- X if (rootbgstr && XParseColor (theDisp, theCmap, rootbgstr, &ecdef) &&
- X XAllocColor (theDisp, theCmap, &ecdef)) rootbg = ecdef.pixel;
- X
- X XSetForeground (theDisp, theGC, fg);
- X XSetBackground (theDisp, theGC, bg);
- X
- X infofg = fg;
- X infobg = bg;
- X
- X if (!mono)
- X {
- X if (theVisual->class == StaticGray || theVisual->class == GrayScale)
- X mono = 1;
- X }
- X
- X if ((mfinfo = XLoadQueryFont (theDisp, FONT))==NULL ||
- X (bfinfo = XLoadQueryFont (theDisp, BFONT))==NULL)
- X {
- X sprintf (str,
- X "couldn't open the following fonts:\n\t %s \n\t %s",
- X FONT, BFONT);
- X FatalError (str);
- X }
- X mfont=mfinfo->fid;
- X bfont=bfinfo->fid;
- X SetNormal ();
- X
- X if (ncols == -1)
- X {
- X if (dispDEEP>1) ncols = 1<<dispDEEP;
- X else ncols = 0;
- X }
- X else if (ncols>256) ncols = 256;
- X
- X CreateDirW (maingeom);
- X
- X while ((i=EventLoop ()) != QUIT);
- X Quit (0);
- X return (0);
- }
- X
- static void Syntax ()
- {
- X fprintf (stderr, "usage: %s\n", cmd);
- X fprintf (stderr, " [-display disp] [-iconic]\n");
- X fprintf (stderr, " [-geometry geom] [-icongeom geom]\n");
- X fprintf (stderr, " [-bg background] [-fg foreground] [-bw width]\n");
- X Quit (-1);
- }
- X
- static int EventLoop ()
- {
- X XEvent event;
- X int retval, done;
- X
- X done = retval = 0;
- X while (!done)
- X {
- X if (XPending (theDisp)>0)
- X {
- X XNextEvent (theDisp, &event);
- X switch (event.type)
- X {
- X case Expose:
- X {
- X XExposeEvent *exp_event = (XExposeEvent *) &event;
- X
- X ExposureWin (exp_event);
- X }
- X break;
- X case ButtonPress:
- X {
- X XButtonEvent *but_event = (XButtonEvent *) &event;
- X int i;
- X
- X switch (but_event->button)
- X {
- X case Button1:
- X if (but_event->window == dirW)
- X {
- X i=ClickDirW (but_event->x, but_event->y);
- X if (i==S_BQUIT) { retval = QUIT;done=1;}
- X }
- X else if (but_event->window == dList.win)
- X {
- X i=LSClick (&dList, but_event);
- X SelectDir (i);
- X }
- X else if (but_event->window == dList.scrl.win)
- X SCTrack (&dList.scrl, but_event->x,
- X but_event->y);
- X break;
- X default:
- X break;
- X }
- X }
- X break;
- X case KeyPress:
- X {
- X XKeyEvent *key_event = (XKeyEvent *) &event;
- X char buf [128];
- X KeySym ks;
- X XComposeStatus status;
- X int stlen;
- X
- X stlen = XLookupString (key_event, buf, 128, &ks, &status);
- X if (!stlen) break;
- X if (key_event->window == dirW)
- X if (DirKey (buf [0])) XBell (theDisp, 0);
- X }
- X break;
- X default:
- X break;
- X }
- X }
- X }
- X return (retval);
- }
- X
- /************************************************************************/
- /* following three rd_* functions swiped from xgraph, by David Harrison */
- /************************************************************************/
- X
- static int rd_int (name)
- char *name;
- {
- X if (def_str = XGetDefault (theDisp, PROGNAME, name))
- X {
- X if (sscanf (def_str, "%ld", &def_int) == 1) return 1;
- X else
- X {
- X fprintf (stderr,
- X "%s: couldn't read integer value for %s resource\n",
- X cmd, name);
- X return 0;
- X }
- X }
- X else return 0;
- }
- X
- static int rd_str (name)
- char *name;
- {
- X if (def_str = XGetDefault (theDisp, PROGNAME, name)) return 1;
- X else return 0;
- }
- X
- static int rd_flag (name)
- char *name;
- {
- X if (def_str = XGetDefault (theDisp, PROGNAME, name))
- X {
- X def_int = (strcmp (def_str, "on")==0) ||
- X (strcmp (def_str, "1")==0) ||
- X (strcmp (def_str, "true")==0) ||
- X (strcmp (def_str, "yes")==0);
- X return 1;
- X }
- X else return 0;
- }
- X
- SHAR_EOF
- chmod 0644 xfbrows.c ||
- echo 'restore of xfbrows.c failed'
- Wc_c="`wc -c < 'xfbrows.c'`"
- test 8155 -eq "$Wc_c" ||
- echo 'xfbrows.c: original size 8155, current size' "$Wc_c"
- fi
- exit 0
-
- --
- Dan Heller
- O'Reilly && Associates Z-Code Software Comp-sources-x:
- Senior Writer President comp-sources-x@uunet.uu.net
- argv@ora.com argv@zipcode.com
-